package com.hnust.root.common.base.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.Page;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;

/**
 * @Author zhusir
 * @Date 2019/1/26
 * @Desc 分页数据
 */
@Data
@NoArgsConstructor
@ToString
public class PageData {

    private long index;

    private long size;

    //总的有几条
    private long count;

    private List list;

    //有几页
    private long pages;

    //pageHelper
    public PageData(Page page) {
        this.index = page.getPageNum();
        this.size= page.getPageSize();
        this.list = page;
        this.count = page.getTotal();
        this.pages = page.getPages();
    }

    //mybatis-plus
    public PageData(IPage page) {
        this.index = page.getCurrent();
        this.size = page.getSize();
        this.pages = page.getPages();
        this.count= page.getTotal();
        this.list = page.getRecords();
    }
}
